using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerView : MonoBehaviour
{
    private IEntity _entity;
    private MoveComponent _moveComponent;

    private void Start()
    {
        Init("1");
    }

    public void Init(string id)
    {
        _entity = RootMgr.Instance.CreateEntity();

        PlayerComponent playerComponent = _entity.AddComponent<PlayerComponent>();
        playerComponent.Transform = transform;
        playerComponent.ID = id;

        _moveComponent = _entity.AddComponent<MoveComponent>();
        _moveComponent.ID = id;

        AniConponent aniConponent = _entity.AddComponent<AniConponent>();
        aniConponent.Animation = gameObject.GetComponent<Animation>();
    }

    private void Update()
    {
        if (_moveComponent != null)
        {
            if (Input.GetKeyDown(KeyCode.A))
            {
                _moveComponent.TargetPos = (new Vector3(-1, 0, 0)) + transform.position;
                _moveComponent.ValueChanged = true;
            }
            else if(Input.GetKeyDown(KeyCode.D))
            {
                _moveComponent.TargetPos = (new Vector3(1, 0, 0)) + transform.position;
                _moveComponent.ValueChanged = true;
            }
            else if (Input.GetKeyDown(KeyCode.W))
            {
                _moveComponent.TargetPos = (new Vector3(0, 1, 0)) + transform.position;
                _moveComponent.ValueChanged = true;
            }
            else if (Input.GetKeyDown(KeyCode.S))
            {
                _moveComponent.TargetPos = (new Vector3(0, -1, 0)) + transform.position;
                _moveComponent.ValueChanged = true;
            }
        }
    }
}
